package com.yanqu.road.entity.activity.evefeast.config;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_s_activity_evefeast_object")
public class EveFeastObjectConfig extends DataObject {
    @FieldTypeAnnotation(select = true, orderASC = true, isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "物品id", isIndex = true)
    private int objectId;
    @FieldTypeAnnotation(desc = "名称")
    private String name;
    @FieldTypeAnnotation(desc = "描述")
    private String desc;
    @FieldTypeAnnotation(desc = "品质")
    private int quality;
    @FieldTypeAnnotation(desc = "基础分")
    private int baseScore;
    @FieldTypeAnnotation(desc = "分类")
    private int type;
    @FieldTypeAnnotation(desc = "流派")
    private int sect;
    @FieldTypeAnnotation(desc = "权重")
    private String weight;
    @FieldTypeAnnotation(desc = "触发类型及参数")
    private String conditionParam;
    @FieldTypeAnnotation(desc = "效果类型及参数")
    private String effectParam;
    @FieldTypeAnnotation(desc = "效果类型及参数")
    private String tieItem;
    @FieldTypeAnnotation(desc = "按钮信息")
    private String buttonInfo;
    @FieldTypeAnnotation(desc = "数量限制,0不限制")
    private int limitNum;


    private List<Integer> weightParams = new ArrayList<>();

    //触发效果
    private List<EveFeastTriggerInfo> triggerInfoList = new ArrayList<>();

    public EveFeastObjectConfig(int activityId, int objectId) {
        this.activityId = activityId;
        this.objectId = objectId;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getObjectId() {
        return objectId;
    }

    public void setObjectId(int objectId) {
        this.objectId = objectId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getQuality() {
        return quality;
    }

    public void setQuality(int quality) {
        this.quality = quality;
    }

    public int getBaseScore() {
        return baseScore;
    }

    public void setBaseScore(int baseScore) {
        this.baseScore = baseScore;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getConditionParam() {
        return conditionParam;
    }

    public void setConditionParam(String conditionParam) {
        this.conditionParam = conditionParam;
    }

    public String getEffectParam() {
        return effectParam;
    }

    public void setEffectParam(String effectParam) {
        this.effectParam = effectParam;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;

        if (!StringUtils.isNullOrEmpty(weight)) {
            setWeightParams(StringUtils.stringToIntegerList(weight, "\\|"));
        }
    }

    public List<Integer> getWeightParams() {
        return weightParams;
    }

    public void setWeightParams(List<Integer> weightParams) {
        this.weightParams = weightParams;
    }

    public int getWeightByMission(int mission) {
        if (mission < 0 || mission >= weightParams.size()) {
            return 0;
        }

        return weightParams.get(mission);
    }

    public List<EveFeastTriggerInfo> getTriggerInfoList() {
        return triggerInfoList;
    }

    /**
     * 解析字符串生成触发效果
     */
    public void initTriggerInfo() {
        triggerInfoList.clear();

        String[] split = this.conditionParam.split("@");
        for (String s : split) {
            String[] split1 = s.split("=");
            int triggerType = Integer.valueOf(split1[0]);
            if (split1.length > 1) {
                triggerInfoList.add(new EveFeastTriggerInfo(triggerType, split1[1]));
            } else {
                triggerInfoList.add(new EveFeastTriggerInfo(triggerType, ""));
            }
        }

        split = this.effectParam.split("@");
        for (int i = 0; i < split.length; i++) {
            String s = split[i];
            if (i >= triggerInfoList.size()) {
                continue;
            }
            EveFeastTriggerInfo triggerInfo = triggerInfoList.get(i);

            List<EveFeastEffectInfo> effectInfoList = new ArrayList<>();

            String[] split1 = s.split("#");
            for (String s1 : split1) {
                String[] split2 = s1.split("=");
                int effectType = Integer.valueOf(split2[0]);
                if (effectType == 0) {//无效果不放进去
                    continue;
                }
                if (split2.length > 1) {
                    effectInfoList.add(new EveFeastEffectInfo(effectType, split2[1]));
                } else {
                    effectInfoList.add(new EveFeastEffectInfo(effectType, ""));
                }
            }

            triggerInfo.setEffectInfoList(effectInfoList);
        }
    }

    public int getSect() {
        return sect;
    }

    public void setSect(int sect) {
        this.sect = sect;
    }

    public String getTieItem() {
        return tieItem;
    }

    public void setTieItem(String tieItem) {
        this.tieItem = tieItem;
    }

    public String getButtonInfo() {
        return buttonInfo;
    }

    public void setButtonInfo(String buttonInfo) {
        this.buttonInfo = buttonInfo;
    }

    public int getLimitNum() {
        return limitNum;
    }

    public void setLimitNum(int limitNum) {
        this.limitNum = limitNum;
    }
}
